/**
 * Created by Administrator on 2016-12-14.
 */

var querystring = require('querystring');
var http = require('http');

var postData = querystring.stringify({
    'msg' : 'Hello World!'
});

var options = {

    host: 'www.baidu.com',
    port: 80,
    path: '/',
    method: 'GET'

};

var req = http.request(options, (res) => {
    console.log(`STATUS: ${res.statusCode}`);
    console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
    res.on('data', (chunk) => {
        console.log(`BODY: ${chunk}`);
    });
    res.on('end', () => {
        console.log('No more data in response.');
    });
});

req.on('error', (e) => {
    console.log(`problem with request: ${e.message}`);
});

// write data to request body
req.write(postData);
req.end();